home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
12511500
/
var1286.dms
/
var1286.adf
/
printers
/
IBMColorJet
/
Render.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
8KB
|
218 lines
/* IBM ColourJet */
/* ColourJet/Render.c */
/*
The IBM ColourJet will only allow the printing of multiple colour per
line in the multicolour raster image mode. This mode requires Red,
Green, and Blue colour inputs. Therefore as the colour class of BGRW
is only supported under 1.2, version 1.2 is required and incorrect
colours will be produced under 1.1.
If any changes or improvements are made to this driver I would
appreciate hearing of these.
Michael Galway
28 Cramer Drive
Nepean, Ontario, CANADA
K2H 5X5
*/
/*****************************************************************************/
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/memory.h"
#include "devices/printer.h"
#include "devices/prtbase.h"
extern struct PrinterData *PD;
extern struct PrinterExtendedData *PED;
int Render(ct, x, y, status)
UBYTE ct; /* colour type - null for b/w printers */
UWORD x, y; /* the x & y co-ordinates */
UBYTE status; /* print status */
/* colour type values
Colour Class
CT BGRW YMCB
== ==== ====
0 - White (Black)
1 - Blue (Yellow)
2 - Green (Magenta)
3 - Red (Cyan)
status values 0 - master initialization / allocate buffer memory
1 - render pixel into buffer
2 - dump buffer to printer
3 - clear and initialize buffer
4 - close down and de-allocate buffer memory
5 - density selection
*/
{
static UWORD ROWSIZE, COLORSIZE, COLORBUFFER, BUFSIZE, bufptr, colors[4];
static UWORD offsetpixels, offsetbytes, pixeloffset, allwhite;
static UBYTE R, G, B, W, red, green, blue, imageoffset;
/* set multi-colour raster image mode and horiz. vert. resolution */
static UBYTE graphicsinit[] ={27, 91, 79, 0, 0, 128, 31, 0, 100, 0};
/* ESC [ O Low High Multicolor HR VR */
static UBYTE setresolution[] ={27, 91, 48, 1, 0, 0};
/* ESC [ 0 1 0 0 */
static UBYTE advanceline[] ={27, 91, 85, 1, 0, 1, 13};
/* ESC [ U 1 0 1 CR */
static UBYTE bitvalues[]={128, 64, 32, 16, 8, 4, 2, 1};
static UBYTE center, lpi, resolution;
static UBYTE imagepad, Pad, PadValue;
UBYTE bitnum;
UWORD i, j, bytenum;
int err;
switch(status) {
case 0 : /* alloc memory for printer buffer */
/* use preferences DRAFT/LETTER quality setting for 72/96 lines/inch */
graphicsinit[9]=lpi;
if (lpi=72)
resolution=1;
else
resolution=3;
setresolution[5]=resolution;
W=0; B=1; G=2; R=3; red=0; green=1; blue=2;
/* # of centering pixels */
offsetpixels = (center) ? ((PED->ped_MaxXDots - x) / 2) : 0;
offsetbytes = offsetpixels >> 3;
pixeloffset = offsetpixels - offsetbytes * 8;
imagepad = !((1 << (8-pixeloffset)) - 1);
/* compute buffer size */
ROWSIZE=x + offsetpixels; /* pixels per line */
imageoffset=10; /* set colour raster images printing mode */
COLORSIZE=(ROWSIZE + 7) >> 3; /* size of a colour buffer in bytes */
COLORBUFFER=COLORSIZE * 3; /* size of RGB colour buffers in bytes */
BUFSIZE=COLORBUFFER +imageoffset +1; /* move down 1 line */
Pad=COLORSIZE *8 - x - offsetpixels; /* padding for # of pixels to be */
/* integer bytes */
PadValue=0;
if (Pad != 0) PadValue= (1 << Pad) - 1; /* 2^Pad -1 */
/* store graphics buffer size for later printer initialization */
graphicsinit[3] = (COLORBUFFER + 5) & 0xff; /* Low Count of data bytes */
graphicsinit[4] = (COLORBUFFER + 5) >> 8; /* High Count of data bytes */
/* compute where to put pixel data in each colour buffer */
colors[R]=COLORSIZE* red +imageoffset +offsetbytes;
colors[G]=COLORSIZE* green +imageoffset +offsetbytes;
colors[B]=COLORSIZE* blue +imageoffset +offsetbytes;
/* allocate buffer memory, double buffering = 2*BUFSIZE */
PD->pd_PrintBuf = (UBYTE *) AllocMem(BUFSIZE*2,MEMF_PUBLIC);
if (err=(PD->pd_PrintBuf == 0)) return(err);
/* set printer to beginning of line and empty buffer */
if (err=(*(PD->pd_PWrite))("\030\015",2)) return(err); /* CTRL-X, CR */
if (err=PWait(1,0)) return(err);
/* set resolution to 72 or 96 lpi for skipping over white lines */
if (err=(*(PD->pd_PWrite))(&setresolution,6)) return(err);
return(err);
bufptr=0;
return(0); /* flag all ok */
break;
case 1 : /* put pixel in buffer */
/* White == Red=Green=Blue=1 */
bytenum=(x + pixeloffset) >> 3; /* (x+pixeloffset)/8 */
bitnum =(x + pixeloffset) & 7; /* (x+pixeloffset)%8 */
if (ct==0) {
i = bufptr+colors[R]+bytenum; /* calc which byte to use for red */
PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
i = bufptr+colors[G]+bytenum; /* calc which byte to use for green */
PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
i = bufptr+colors[B]+bytenum; /* calc which byte to use for blue */
PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
allwhite++;
}
else {
i = bufptr+colors[ct]+bytenum; /* calc byte to use for colour==ct */
PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
}
return(0);
break;
case 2 : /* common dump buffer to printer */
if (allwhite != ROWSIZE) {
if (err=(*(PD->pd_PWrite))(&(PD->pd_PrintBuf[bufptr]), BUFSIZE))
return(err);
bufptr=BUFSIZE-bufptr; /* bufptr alternates between 0 and BUFSIZE */
}
else
if (err=(*(PD->pd_PWrite))(&advanceline,7)) return(err);
return(err);
break;
case 3 : /* clear and init buffer */
/* set buffer to black */
for (i=bufptr; i<bufptr+BUFSIZE; i++) PD->pd_PrintBuf[i] = 0;
/* pad from left to start of image with white */
for (j=0; j<3; j++) {
for (i=0; i<offsetbytes; i++)
PD->pd_PrintBuf[bufptr+COLORSIZE*j+imageoffset+i]=255;
PD->pd_PrintBuf[bufptr+COLORSIZE*j+imageoffset+offsetbytes]=imagepad;
}
/* pad unused bit positions in last byte with white */
for (i=1; i<4; i++)
PD->pd_PrintBuf[bufptr+COLORSIZE*i+imageoffset-1]= PadValue;
/* store graphics control codes at beginning of buffer */
for (i=0; i<10; i++) PD->pd_PrintBuf[bufptr+i] = graphicsinit[i];
/* put advance line cammand at end of buffer */
PD->pd_PrintBuf[bufptr+BUFSIZE-1]=13;
/* assume line not all white, therefore print normally */
allwhite=0;
return(0);
break;
case 4 : /* common free the print buffer memory and exit */
err=(*(PD->pd_PWrite))("\015",1); /* carriage return */
if (!err) err=(*(PD->pd_PBothReady))(); /* wait for buffers to empty */
FreeMem(PD->pd_PrintBuf,BUFSIZE*2); /* free print buffer's memory */
return(err); /* return status */
break;
case 5 : /* io_special flags call, density selection */
/* Centre the image? */
center = (x & SPECIAL_CENTER); /* set center flag */
/* select 72 or 96 lpi if DRAFT or NLQ selected */
if (PD->pd_Preferences.PrintQuality == DRAFT)
lpi = 72;
else
lpi = 96;
PED->ped_YDotsInch = (UWORD) lpi;
return(0);
break;
default:
return(0);
break;
}
}
/***************** End of File: ColourJet/Render.c *********************/